package wx

import (
	"gitee.com/go_love/db"
	"gitee.com/go_love/wxapi"
	"gitee.com/xmcommon/mlog"
)

func GetWXAccessToken() (accessToken string) {
	row := db.DbApp.QueryRow(`SELECT access_token FROM wx_access_token;`)
	_ = row.Scan(&accessToken)
	return
}

func RefreshWXAccessToken() (accessToken string, err error) {
	accessToken, _, err = wxapi.GetWXAccessToken()
	if err != nil {
		mlog.Log.Error(err.Error())
		return
	}
	_, err = db.DbApp.Exec(`UPDATE wx_access_token SET access_token = ?;`, accessToken)
	if err != nil {
		mlog.Log.Error(err.Error())
		return
	}
	return
}
